package avicit.bdp.dgs.metadata.service;

import avicit.bdp.common.base.BaseService;
import avicit.bdp.common.service.dto.BdpColumnHistoryDTO;
import avicit.bdp.dgs.metadata.dao.MetadataTableColumnHistoryDao;
import avicit.platform6.core.exception.BusinessException;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 数据表元数据表列表service
 *
 * @author mayanj
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class MetadataTableColumnHistoryService
    extends BaseService<MetadataTableColumnHistoryDao, BdpColumnHistoryDTO> {

  /**
   * 根据所属表id删除
   *
   * @param tableId 表id
   */
  public void deleteByTableId(String tableId) {
    if (StringUtils.isEmpty(tableId)) {
      throw new BusinessException("删除失败！传入的参数主键为null");
    }
    try {
      BdpColumnHistoryDTO columnHistory = new BdpColumnHistoryDTO();
      columnHistory.setTableId(tableId);
      delete(columnHistory);
    } catch (Exception e) {
      throw new BusinessException(e.getMessage(), e);
    }
  }

  /**
   * 批量添加
   *
   * @param columnList 列集合
   */
  public void batchInsert(List<BdpColumnHistoryDTO> columnList) {
    this.mapper.batchInsert(columnList);
  }

  public int deleteByDatasourceId (String datasourceId) {
    return this.mapper.deleteByDatasourceId(datasourceId);
  }
}
